<?php

namespace liketry\controllers;

use Yii;
use services\models\IndexQuery;
use services\models\ClockIn;
//use common\models\IndexManage;

class IndexController extends CustomController
{
    public function actionIndex()
    {
        $indexQuery = new IndexQuery();
        
        $banner_list = $indexQuery->getBannerListByRedis(); //BANNER
        $logo_adv = $indexQuery->getLogoAdv();              //LOGO右侧广告
        $day_try_list = $indexQuery->getDayTry();           //每日一试
        $try_rec_list = $indexQuery->getTryRec();           //小试推荐
        $try_adv_list = $indexQuery->getTryAdv();           //大试特试（先试后买、试用报告）
        $super_try_list = $indexQuery->getSuperTry();       //超值试用
        
        $ad_uid = Array(18,19);
        $liketry_ad_list = $indexQuery->getIndexAd($ad_uid);

        return $this->render('index', [
            'banner_list' => $banner_list,
            'logo_adv' => $logo_adv,
            'day_try_list' => $day_try_list,
            'try_rec_list' => $try_rec_list,
            'liketry_ad_list' => $liketry_ad_list,
            'try_adv_list' => $try_adv_list,
            'super_try_list' => $super_try_list
            
        ]);
    }
    
    public function actionDaka()
    {
        $json_array = ['data' => '', 'msg' => '' ,'flag' => 0];
        $lkt_uid = intval(Yii::$app->session->get(Yii::$app->params['member_no']));
        if($lkt_uid <= 0)
        {
            $json_array['msg'] = '请先登陆';
            return json_encode($json_array);
        }
        $is_daka = ClockIn::is_DaKa($lkt_uid);
        if($is_daka)
        {
            $json_array['msg'] = '您已经打过卡了';
            return json_encode($json_array);
        }
        
        $myClock = new ClockIn();
        $res = $myClock->DaKa($lkt_uid);
        if(!$res)
        {
            $json_array['msg'] = '打卡失败';
            return json_encode($json_array);
        }
        $json_array['flag'] = '1';
        $json_array['msg'] = '打卡成功';
        return json_encode($json_array);
    }
     public function actionShaidan(){
         return $this->render('shaidan');
     }
}

